<?php
class search extends Controller{

	function index(){
		if(!$this->user->isLogged()){
			$this->response->redirect(MAIN_PAGE);
		}
		$this->load->model("doctype");
		$this->data["doctype_list"]=$this->model_doctype->loaddoctype()->rows;
		$dept_id=$this->user->getDepartmentId();
		$this->load->model("searchdoc");
		$this->data["search_list"]=$this->model_searchdoc->getdocbydeptid($dept_id)->rows;
		$this->document->setTitle("Document Management Solutions");
		$this->document->setSelectedMenu("menu_search");
		$this->document->addLink("jqueryui/jquery.ui.all.css");
		$this->document->scripts=array("jquery-ui/jquery-ui-1.8.16.custom.min.js","jquery.timepicker.min.js");
		$this->children=array("header","footer");
		$this->template="search.html";
		$this->response->setOutput($this->render(TRUE),0);
	}

	function searchpost(){
		$jsonarr=array();
		if($this->request->is_ajax_request() && $this->user->isLogged()){
			$this->load->model("searchdoc");
			$res=$this->model_searchdoc->getsearchlist()->rows;
			$jsonarr["searchresult"]=$res;
			$jsonarr["searchcount"]=count($res);
			$jsonarr["status"]=true;
		}
		else{
			$jsonarr["status"]=false;
			$jsonarr["redirect"]=true;
		}
		echo json_encode($jsonarr);
	}
	function historypost(){
		$jsonarr=array();
		if($this->request->is_ajax_request() && $this->user->isLogged()){
			$this->load->model("searchdoc");
			$res=$this->model_searchdoc->getsearchlist(true)->rows;
			$jsonarr["searchresult"]=$res;
			$jsonarr["searchcount"]=count($res);
			$jsonarr["status"]=true;
		}
		else{
			$jsonarr["status"]=false;
			$jsonarr["redirect"]=true;
		}
		echo json_encode($jsonarr);
	}

}
?>